package com.xiaolun.blockingQueue;


import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

public class BlockingQueueDemo01 {
	public static void main(String[] args) {

//        List list = new ArrayList();
		BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(3);
		//第一组
//        System.out.println(blockingQueue.add("a")); //true
//        System.out.println(blockingQueue.add("b"));
//        System.out.println(blockingQueue.add("c"));
        //检查队首元素；输出a
//        System.out.println(blockingQueue.element());

//		System.out.println(blockingQueue.add("x"));
//        System.out.println(blockingQueue.remove()); //a
//        System.out.println(blockingQueue.remove());
//        System.out.println(blockingQueue.remove());
//        System.out.println(blockingQueue.remove());
//    第二组
//        System.out.println(blockingQueue.offer("a")); //true
//        System.out.println(blockingQueue.offer("b"));
//        System.out.println(blockingQueue.offer("c"));
//        System.out.println(blockingQueue.offer("x")); //false
//        System.out.println(blockingQueue.poll()); //a
//        System.out.println(blockingQueue.poll());
//        System.out.println(blockingQueue.poll());
//        System.out.println(blockingQueue.poll()); //null
//    第三组
//         blockingQueue.put("a");
//         blockingQueue.put("b");
//         blockingQueue.put("c");
		//阻塞队列已满，将会一直阻塞，直到腾出位置为止。
//         //blockingQueue.put("x");
//        System.out.println(blockingQueue.take());
//        System.out.println(blockingQueue.take());
//        System.out.println(blockingQueue.take());
		//一直阻塞
//        System.out.println(blockingQueue.take());

//    第四组
//		System.out.println(blockingQueue.offer("a"));
//		System.out.println(blockingQueue.offer("b"));
//		System.out.println(blockingQueue.offer("c"));
		//亮3秒，阻塞结束
//		System.out.println(blockingQueue.offer("a", 3L, TimeUnit.SECONDS));
	}
}
